package com.uchengwang.ui.cm_ui.me.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.uchengwang.R;
import com.uchengwang.functions.http.config.BaseConfig;
import com.uchengwang.functions.image.ImageManager;
import com.uchengwang.ui.cm_ui.cycle.adapter.BaseCycleAdapter;
import com.uchengwang.ui.cm_ui.cycle.viewHolder.BaseViewHolder;
import com.uchengwang.ui.cm_ui.login.bean.UserBean;
import com.uchengwang.ui.cm_ui.me.ui.TransferCodeActivity;
import com.uchengwang.ui.utils.UCommonUtil;

/**
 * Created by U城网 on 2018/4/24.
 */

public class TranferAdapter extends BaseCycleAdapter<UserBean, RecyclerView.ViewHolder> {
    private Context context;

    public TranferAdapter(Context context){
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_layout_view, parent, false);
        return new BaseViewHolder(view, 8);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder h, int position) {
        final BaseViewHolder holder = (BaseViewHolder) h;
        final UserBean bean = list.get(position);

        String headUrl = bean.getUserAvatar();
        if (TextUtils.isEmpty(headUrl)){
            ImageManager.getInstance().loadImage(context, holder.head, R.drawable.no_head, ImageManager.ImageType.CIRCLE);
        }else {
            ImageManager.getInstance().loadImage(context, holder.head, headUrl, ImageManager.ImageType.CIRCLE);
        }

        String remark = bean.getRemarkName();
        String realName = bean.getRealName();
        if (TextUtils.isEmpty(remark)){
            if (!TextUtils.isEmpty(realName)){
                holder.name.setText(realName);
            }else {
                holder.name.setText(bean.getNickName());
            }
        }else {
            holder.name.setText(remark);
        }

        if (!TextUtils.isEmpty(bean.getMobile())){
            holder.des.setText(bean.getMobile());
        }else {
            holder.des.setText("");
        }

        holder.apply_sex.setVisibility(View.GONE);

        holder.bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, TransferCodeActivity.class);
                intent.putExtra(BaseConfig.UID, bean.getId());
                context.startActivity(intent);

            }
        });

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UCommonUtil.getUtil().toUserActivity((Activity) context, bean.getId());
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }
}
